/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mnstudent.presentationlayer;

import mnstudent.global.Standard;
import mnstudent.businessLayer.LoginBLL;
import mnstudent.businessLayer.PositionBLL;
import mnstudent.businessLayer.RegulationBLL;
import mnstudent.businessLayer.StaffBLL;
import mnstudent.datatranferobject.LoginDTO;
import mnstudent.datatranferobject.PositionDTO;
import mnstudent.datatranferobject.StaffDTO;
import mnstudent.security.MD5;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class frmInfoStaff extends javax.swing.JPanel {

    private StaffBLL m_StaffBLL;
    private PositionBLL m_PositionBLL;
    private RegulationBLL m_RegulationBLL;

    private ArrayList<PositionDTO> listPositionObj;
    PositionDTO objAddNew;//doi tuong khoa khi chon se mo len Cua so them moi khoa
    private int currentRow = 0;
    private boolean m_isUpdate = false;
    private DefaultTableModel m_Model;
    private final SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");
    private int minAge, maxAge;

    /**
     * Creates new form frmFaculty
     */
    public frmInfoStaff() {
        initComponents();
        initControls();
        prepair();
    }

    /**
     * Init Controls
     */
    private void initControls() {

        jxTxtStaffID.setEditable(false);//luon luon false
        jxTxtUserName.setEditable(false);
        jPfPassword.setEditable(false);
        //neu chua them moi thi EditTable = false
        if (!m_isUpdate) {

            jxTxtNameOfStaff.setEditable(false);
            jxTxtPhone.setEditable(false);
            jxTxtAddress.setEditable(false);

            jxCbGender.setEnabled(false);
            jxCbPosition.setEnabled(false);
            jxDpBirthday.setEditable(false);

            jxBtnSave.setEnabled(false);
            jxBtnCancel.setEnabled(false);

            jxBtnUpdate.setEnabled(true);
        } else {

            jxTxtNameOfStaff.setEditable(true);
            jxTxtPhone.setEditable(true);
            jxTxtAddress.setEditable(true);

            jxCbGender.setEnabled(true);
            jxCbPosition.setEnabled(true);
            jxDpBirthday.setEditable(true);

            jxBtnSave.setEnabled(true);
            jxBtnCancel.setEnabled(true);

            jxBtnUpdate.setEnabled(false);
        }
    }

    /**
     * Ham set max lenght lon nhat cho cac textField
     */
    public void setMaxLenghtForTextField() {
        //TextField So dien thoai
        jxTxtPhone.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
                char vChar = e.getKeyChar();
                int len = jxTxtPhone.getText().length();
                if (!(Character.isDigit(vChar)
                        || (vChar == KeyEvent.VK_BACK_SPACE)
                        || (vChar == KeyEvent.VK_DELETE)
                        || (vChar == KeyEvent.VK_ENTER)
                        || (vChar == KeyEvent.VK_TAB)) || (len > Standard.MAX_LEN_PHONE)) {
                    e.consume();
                }
            }
        });
        //TextField Ho ten nhan vien
        jxTxtNameOfStaff.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
                int len = jxTxtNameOfStaff.getText().length();
                if (len > Standard.MAX_LEN) {
                    e.consume();
                }
            }
        });
        //TextField Dia chi nhan vien
        jxTxtAddress.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
                int len = jxTxtAddress.getText().length();
                if (len > Standard.MAX_LEN) {
                    e.consume();
                }
            }
        });
    }

    private void bindingDataToComboBox() {

        //ComboxBox Doi tuong
        m_PositionBLL = new PositionBLL();
        listPositionObj = m_PositionBLL.getAllIdAndNameOfPositionToArray();
        objAddNew = new PositionDTO("CVThemMoi", "Thêm mới...");
        listPositionObj.add(objAddNew);
        DefaultComboBoxModel dfCbModel = new DefaultComboBoxModel(listPositionObj.toArray());
        jxCbPosition.setModel(dfCbModel);

        //ComboBox Gioi tinh
        String[] arrGender = {"Nam", "Nữ"};
        DefaultComboBoxModel dfCbModelGender = new DefaultComboBoxModel(arrGender);
        jxCbGender.setModel(dfCbModelGender);
    }

    private void bindingDataToControls() {
        jxTxtStaffID.setText(LoginDTO.getID());
        jxTxtNameOfStaff.setText(LoginDTO.getName());
        jxTxtPhone.setText(LoginDTO.getPhone());
        jxTxtAddress.setText(LoginDTO.getAddress());
        jxTxtUserName.setText(LoginDTO.getUserName());
        jPfPassword.setText(LoginDTO.getPass());

        String gender = LoginDTO.getSex();
        jxCbGender.setSelectedItem(gender);

        PositionDTO objPosition = m_PositionBLL.getPositionDTOById(LoginDTO.getIDPermission());
        jxCbPosition.setSelectedItem(objPosition);

        //Ngay sinh 
        if (!LoginDTO.getBirthday().equals("")) {
            String d = formatDate.format(LoginDTO.getBirthday());
            Date date;
            try {
                date = (Date) formatDate.parse(d);
                jxDpBirthday.setDate(date);
            } catch (ParseException ex) {
                ex.printStackTrace();
            }
        }
    }

    private void prepair() {
        UIManager.put("OptionPane.cancelButtonText", "Hủy");
        UIManager.put("OptionPane.noButtonText", "Không");
        UIManager.put("OptionPane.okButtonText", "Có");
        UIManager.put("OptionPane.yesButtonText", "Vâng");
        setMaxLenghtForTextField();
        bindingDataToComboBox();
        bindingDataToControls();

        m_RegulationBLL = new RegulationBLL();
        minAge = Integer.valueOf(m_RegulationBLL.getRegulationByLabelToObject("TuoiToiThieuNhanVien").getValue());
        maxAge = Integer.valueOf(m_RegulationBLL.getRegulationByLabelToObject("ToiToiDaNhanVien").getValue());
    }

    /**
     * Ham thuc hien cap nhat Khoa
     *
     * @return
     */
    private void update() {
        m_StaffBLL = new StaffBLL();

        if (checkData()) {
            String id = this.jxTxtStaffID.getText().trim();;//Ma nhan vien
            String name = Standard.standardNamePerson(this.jxTxtNameOfStaff.getText());//ten nhan vien
            String gender = this.jxCbGender.getSelectedItem().toString();//gioi tinh
            //Chuc vu
            PositionDTO objPosition = (PositionDTO) this.jxCbPosition.getSelectedItem();
            String idPosition = objPosition.getPositionID();//Ma chuc vu
            String phone = jxTxtPhone.getText().trim();
            String address = Standard.standardName(jxTxtAddress.getText().trim());
            java.sql.Date d = new java.sql.Date(jxDpBirthday.getDate().getYear(),
                    jxDpBirthday.getDate().getMonth(), jxDpBirthday.getDate().getDate());//Ngay sinh

            StaffDTO staffObj = new StaffDTO(id, name, gender,
                    d, phone, address, idPosition);
            if (m_StaffBLL.updateStaffNoPasswordToDatabase(staffObj)) {

                JOptionPane.showOptionDialog(null,
                        "Câp nhật thành công!",
                        "Thông báo",
                        JOptionPane.YES_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        null,
                        null);
                //neu Cập nhật thanh cong
                m_isUpdate = false;
                initControls();
                //load lai thang LoginDTO
                LoginBLL loginBLL = new LoginBLL();
                loginBLL.loadUser(LoginDTO.getUserName(), LoginDTO.getPass());
                bindingDataToControls();
            } else {
                JOptionPane.showMessageDialog(null, "Cập nhật thất bại. Vui lòng kiểm tra lại!", "Lỗi", JOptionPane.YES_OPTION);
            }
        }
    }

    private boolean checkData() {
        if (jxTxtStaffID.getText().equals("")
                || jxTxtNameOfStaff.getText().equals("")
                || jxTxtAddress.getText().equals("")
                || jxTxtPhone.getText().equals("")
                || jxTxtUserName.getText().equals("")
                || jxCbGender.getSelectedIndex() == -1
                || jxCbPosition.getSelectedIndex() == -1
                || jxDpBirthday.getDate().equals(null)) {
            JOptionPane.showOptionDialog(null,
                    "Dữ liệu không được bỏ trống. Vui lòng nhập lại!",
                    "Cảnh báo",
                    JOptionPane.YES_OPTION,
                    JOptionPane.WARNING_MESSAGE,
                    null,
                    null,
                    null);
            return false;
        } else {
            if(Standard.compareDate(jxDpBirthday.getDate(), Standard.getDateSystem()) == 1||
                    Standard.compareDate(jxDpBirthday.getDate(), Standard.getDateSystem()) == 0){//ngay sinh phai nho hon hoac bang ngay hien tai
                int age = Standard.calculateAge(jxDpBirthday.getDate());
                if (age >= minAge && age <= maxAge) {
                    return true;
                } else {
                     JOptionPane.showMessageDialog(null, "Tuổi nhân viên không hợp lệ!");
                    return false;
                }
            }
            else
            {
                 JOptionPane.showMessageDialog(null, "Ngày sinh phải nhỏ hơn hoặc bằng ngày hiện tại!");
                    return false;
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jxpanHeader = new org.jdesktop.swingx.JXPanel();
        jxpanTitleHeader = new org.jdesktop.swingx.JXPanel();
        jXLabel5 = new org.jdesktop.swingx.JXLabel();
        jxpanInfoHeader = new org.jdesktop.swingx.JXPanel();
        jxpanInfo = new org.jdesktop.swingx.JXPanel();
        jxLabFacultyID = new org.jdesktop.swingx.JXLabel();
        jxTxtStaffID = new org.jdesktop.swingx.JXTextField();
        jxLabNameOfFaculty = new org.jdesktop.swingx.JXLabel();
        jxTxtNameOfStaff = new org.jdesktop.swingx.JXTextField();
        jxLabNameOfFaculty1 = new org.jdesktop.swingx.JXLabel();
        jxCbPosition = new org.jdesktop.swingx.JXComboBox();
        jxLabFacultyID1 = new org.jdesktop.swingx.JXLabel();
        jxCbGender = new org.jdesktop.swingx.JXComboBox();
        jxLabNameOfFaculty2 = new org.jdesktop.swingx.JXLabel();
        jxDpBirthday = new org.jdesktop.swingx.JXDatePicker();
        jxLabNameOfFaculty4 = new org.jdesktop.swingx.JXLabel();
        jxTxtAddress = new org.jdesktop.swingx.JXTextField();
        jxLabNameOfFaculty5 = new org.jdesktop.swingx.JXLabel();
        jxTxtUserName = new org.jdesktop.swingx.JXTextField();
        jxLabNameOfFaculty6 = new org.jdesktop.swingx.JXLabel();
        jxTxtPhone = new org.jdesktop.swingx.JXTextField();
        jxLabNameOfFaculty7 = new org.jdesktop.swingx.JXLabel();
        jxBtnChangePassword = new org.jdesktop.swingx.JXButton();
        jPfPassword = new javax.swing.JPasswordField();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        jxBtnUpdate = new org.jdesktop.swingx.JXButton();
        jxBtnCancel = new org.jdesktop.swingx.JXButton();
        jxBtnSave = new org.jdesktop.swingx.JXButton();

        setLayout(new java.awt.BorderLayout());

        jxpanHeader.setLayout(new java.awt.BorderLayout());

        jxpanTitleHeader.setBorder(new org.jdesktop.swingx.border.DropShadowBorder());

        jXLabel5.setForeground(new java.awt.Color(0, 102, 255));
        jXLabel5.setText("THÔNG TIN NHÂN VIÊN");
        jXLabel5.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jxpanTitleHeader.add(jXLabel5);

        jxpanHeader.add(jxpanTitleHeader, java.awt.BorderLayout.PAGE_START);

        jxpanInfoHeader.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanInfoHeader.setLayout(new java.awt.BorderLayout());

        jxpanInfo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "THÔNG TIN", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));

        jxLabFacultyID.setText("Mã nhân viên");

        jxLabNameOfFaculty.setText("Tên nhân viên");

        jxLabNameOfFaculty1.setText("Chức vụ");

        jxCbPosition.setVerifyInputWhenFocusTarget(false);

        jxLabFacultyID1.setText("Giới tính");

        jxCbGender.setVerifyInputWhenFocusTarget(false);

        jxLabNameOfFaculty2.setText("Ngày sinh");

        jxDpBirthday.setFormats("dd/MM/yyyy");

        jxLabNameOfFaculty4.setText("Địa chỉ");

        jxLabNameOfFaculty5.setText("Điện thoại");

        jxLabNameOfFaculty6.setText("Tên đăng nhập");

        jxLabNameOfFaculty7.setText("Mật khẩu");

        jxBtnChangePassword.setText("Đổi mật khẩu");
        jxBtnChangePassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnChangePasswordActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jxpanInfoLayout = new javax.swing.GroupLayout(jxpanInfo);
        jxpanInfo.setLayout(jxpanInfoLayout);
        jxpanInfoLayout.setHorizontalGroup(
            jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanInfoLayout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jxLabFacultyID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabFacultyID1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabNameOfFaculty5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jxTxtStaffID, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jxCbGender, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jxTxtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(80, 80, 80)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jxLabNameOfFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabNameOfFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabNameOfFaculty4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jxDpBirthday, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxTxtNameOfStaff, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jxTxtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(80, 80, 80)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addComponent(jxLabNameOfFaculty1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51))
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jxLabNameOfFaculty7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabNameOfFaculty6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)))
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jxBtnChangePassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxTxtUserName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jxCbPosition, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                    .addComponent(jPfPassword))
                .addContainerGap(57, Short.MAX_VALUE))
        );
        jxpanInfoLayout.setVerticalGroup(
            jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanInfoLayout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxLabNameOfFaculty1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxCbPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxTxtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabNameOfFaculty6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxLabNameOfFaculty7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPfPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxLabFacultyID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxTxtStaffID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabNameOfFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxTxtNameOfStaff, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxLabFacultyID1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxCbGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabNameOfFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxDpBirthday, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxTxtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabNameOfFaculty4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxTxtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabNameOfFaculty5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addComponent(jxBtnChangePassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(144, Short.MAX_VALUE))
        );

        jxpanInfoHeader.add(jxpanInfo, java.awt.BorderLayout.CENTER);

        jXPanel1.setLayout(new java.awt.BorderLayout());

        jxBtnUpdate.setText("Cập nhật thông tin");
        jxBtnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnUpdateActionPerformed(evt);
            }
        });

        jxBtnCancel.setText("Hủy bỏ");
        jxBtnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnCancelActionPerformed(evt);
            }
        });

        jxBtnSave.setText("Lưu thông tin");
        jxBtnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnSaveActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel2Layout = new javax.swing.GroupLayout(jXPanel2);
        jXPanel2.setLayout(jXPanel2Layout);
        jXPanel2Layout.setHorizontalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel2Layout.createSequentialGroup()
                .addContainerGap(827, Short.MAX_VALUE)
                .addComponent(jxBtnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50)
                .addComponent(jxBtnSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50)
                .addComponent(jxBtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42))
        );
        jXPanel2Layout.setVerticalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel2Layout.createSequentialGroup()
                .addContainerGap(41, Short.MAX_VALUE)
                .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxBtnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxBtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxBtnSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36))
        );

        jXPanel1.add(jXPanel2, java.awt.BorderLayout.CENTER);

        jxpanInfoHeader.add(jXPanel1, java.awt.BorderLayout.SOUTH);

        jxpanHeader.add(jxpanInfoHeader, java.awt.BorderLayout.CENTER);

        add(jxpanHeader, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void jxBtnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnUpdateActionPerformed
        this.m_isUpdate = true;
        initControls();
        jxTxtNameOfStaff.requestFocus();
    }//GEN-LAST:event_jxBtnUpdateActionPerformed

    private void jxBtnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnSaveActionPerformed

        update();
    }//GEN-LAST:event_jxBtnSaveActionPerformed

    private void jxBtnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnCancelActionPerformed
        this.m_isUpdate = false;
        initControls();
        bindingDataToControls();
    }//GEN-LAST:event_jxBtnCancelActionPerformed

    private frmChangePassword m_frmChangePassword;
    private void jxBtnChangePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnChangePasswordActionPerformed

        m_frmChangePassword = new frmChangePassword(null, true);
        m_frmChangePassword.show();
    }//GEN-LAST:event_jxBtnChangePasswordActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPasswordField jPfPassword;
    private org.jdesktop.swingx.JXLabel jXLabel5;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    private org.jdesktop.swingx.JXButton jxBtnCancel;
    private org.jdesktop.swingx.JXButton jxBtnChangePassword;
    private org.jdesktop.swingx.JXButton jxBtnSave;
    private org.jdesktop.swingx.JXButton jxBtnUpdate;
    private org.jdesktop.swingx.JXComboBox jxCbGender;
    private org.jdesktop.swingx.JXComboBox jxCbPosition;
    private org.jdesktop.swingx.JXDatePicker jxDpBirthday;
    private org.jdesktop.swingx.JXLabel jxLabFacultyID;
    private org.jdesktop.swingx.JXLabel jxLabFacultyID1;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty1;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty2;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty4;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty5;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty6;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty7;
    private org.jdesktop.swingx.JXTextField jxTxtAddress;
    private org.jdesktop.swingx.JXTextField jxTxtNameOfStaff;
    private org.jdesktop.swingx.JXTextField jxTxtPhone;
    private org.jdesktop.swingx.JXTextField jxTxtStaffID;
    private org.jdesktop.swingx.JXTextField jxTxtUserName;
    private org.jdesktop.swingx.JXPanel jxpanHeader;
    private org.jdesktop.swingx.JXPanel jxpanInfo;
    private org.jdesktop.swingx.JXPanel jxpanInfoHeader;
    private org.jdesktop.swingx.JXPanel jxpanTitleHeader;
    // End of variables declaration//GEN-END:variables
}
